package com.cc.thread;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;

import com.cc.app.R;
import com.victor.loading.rotate.RotateLoading;

/**
 * Created by lenovo on 2017/11/27.
 */

public class MyAsyncThread extends AsyncTask {
    private Context mContext ;
    private Dialog dialog;
    private RotateLoading rotateLoading;

    public MyAsyncThread(Context context){
        this.mContext = context;
    }

    @Override
    protected void onPreExecute() {
        initDialog();
        System.out.println("1111111111111111111");
        super.onPreExecute();
    }

    @Override
    protected Object doInBackground(Object[] objects) {
        for (int i = 0; i < 100000; i++) {
            System.out.println("Progress："+i);
        }
        return null;
    }

    @Override
    protected void onProgressUpdate(Object[] values) {

        super.onProgressUpdate(values);
    }

    @Override
    protected void onPostExecute(Object o) {
        System.out.println("3333333333333");
        dialog.dismiss();
        rotateLoading.stop();
        super.onPostExecute(o);
    }

    private void initDialog(){
        View view = LayoutInflater.from(mContext).inflate(R.layout.loading_dialog , null);
        rotateLoading = view.findViewById(R.id.rotateloading);
        rotateLoading.start();
        dialog = new Dialog(mContext);
        dialog.setContentView(view);
        dialog.show();
    }


}
